package com.sophic_tech.hkb.utils


fun String.isPhoneNumber(): Boolean = this.matches("^1[3-9]\\d{9}$".toRegex())

fun String.Companion.randomUsername(
    length: Int = 8,
    includeNumbers: Boolean = true,
    includeUnderscore: Boolean = true
): String {
    require(length >= 1) { "用户名长度不能小于 1" }

    val baseChars = 'a'..'z'
    val optionalChars = buildList<Char> {
        addAll(baseChars)
        if (includeNumbers) addAll('0'..'9')
        if (includeUnderscore) add('_')
    }
    val firstChar = baseChars.random()
    val remainingChars = (1 until length).map { optionalChars.random() }
    return (listOf(firstChar) + remainingChars).joinToString("")
}

class StringUtils {
    companion object {
        @JvmStatic
        fun randomUsername(
            length: Int,
            includeNumbers: Boolean,
            includeUnderscore: Boolean
        ): String {
            return String.randomUsername(length, includeNumbers, includeUnderscore)
        }
    }
}